import { ref, h } from "vue";
import { FormItemComponentType, FormItemData } from "/@/components/CURDDialog/models";
import { GatewayTypeItem } from "/@/api/aiot/gateway/models";
import { PatternKey } from "/@/utils/verify";
import { getManufacturerCode } from "/@/api/aiot/gateway";

export function useGatewayModel(isEnterprise: boolean) {
  const gtModel = ref<Partial<GatewayTypeItem>>({
    gatewayTypeName: "",
    gatewayTypeCode: "",
    manufacturerCode: "",
    isActive: true,
  });
  const gtFormSetting = ref<FormItemData[]>([
    {
      key: "gatewayTypeName",
      required: true,
      label: "网关类型名称",
      pattern: PatternKey.name,
      max: 32,
    },
    {
      key: "gatewayTypeCode",
      required: true,
      label: "网关类型代码",
      labelDes: "支持大小写字母、数字和下划线",
      pattern: PatternKey.code,
      max: 32,
    },
    {
      key: "manufacturerCode",
      required: true,
      label: "厂商标识",
      type: FormItemComponentType.SELECT,
      async getData() {
        const data = await getManufacturerCode(!isEnterprise);
        return data
          ? data.map((el) => ({
              label: el.text,
              value: el.value,
            }))
          : [];
      },
      props: {
        options: [],
      },
    },
    {
      key: "isActive",
      type: FormItemComponentType.SWITCH,
      label: "是否启用",
    },
  ]);
  return {
    gtModel,
    gtFormSetting,
  };
}
